;(function (){
	var CGI = {
			USER_REGISTER: window.frontPath + 'promLink/register',	//会与注册
		};
	
		$("#scrollsidebar").load(window.basePath+"static/onlineCustomer/index.html",function(){
			jQuery("#onlineCustomer").attr("src",window.basePath+"static/img/kf/ico-kefu1.png").click(
			 function()
			 {
				  window.open("http://tb.53kf.com/webCompany.php?arg=10093400&style=1",window.platform);
			 }
			);
			jQuery("#platform").html(window.platform);
			$("#scrollsidebar").fix({suspend:"left",minStatue:true,durationTime:600});
		});
		$.placeholder.init();
		jQuery("#registerBtn").click(function()
		{
			if($.validation.isSuccess($('#registerForm'))){
				$.ajax({ 
				    url: CGI.USER_REGISTER, 
				    type: 'POST', 
				    data 	: $('#registerForm').serialize(),
				    success: function(data) {
				    	if(0 === data.retcode){
				    		$.alert({
					    		status : 'ok',
								basicTitle : '恭喜你成功注册为平台会员！'
							});
				    		window.setTimeout(function (){
				    			$.none_alert(function (){
				    				window.location.href = window.frontPath+ 'home';
				    			});
				    		},2000);
				    	}else{
				    		$.exception(data.retcode , data.retmsg);
				    	}
				    }
				});
			}
		
		}		
		);
		
		var REGISTER_ERROR = {
				LOGIN_NAME 	: {
					NULL : '登录名不能为空',
					ERROR : '登录名格式错误'
				},
				USER_PWD  	: {
					NULL  : '密码不能为空',
					ERROR : '密码格式错误'
				},
				CONF_PWD 	: {
					NULL  : '确认密码不能为空',
					ERROR : '确认密码跟密码不一致'
				},
				QQ 			: {
					ERROR : 'QQ号格式不对'
				},
				USER_NAME 	: {
					NULL  : '昵称不能为空',
					ERROR : '昵称必须为8个字符以下'
				} 
			};
		
		$.validation.init([{				//用户名校验
			ele : '[name="loginName"]',
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val === ''||_val==$.trim(this.ele.attr("data-placeholder"))){
					return REGISTER_ERROR.LOGIN_NAME.NULL;
				}
				if($.check.isUserN(this.ele.val())){
					return true;
				}else{
					return REGISTER_ERROR.LOGIN_NAME.ERROR;
				}
			}
		},
		{									//用户姓名校验
			ele : '[name="userName"]',
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val === ''||_val==$.trim(this.ele.attr("data-placeholder"))){
					return REGISTER_ERROR.USER_NAME.NULL;
				}
				/*if(!$.check.isUserZN(_val)){
					return ADD_VIP_ERROR.USER_NAME.ERROR;
				}*/
				return true;
			}
		},
		{									//密码校验
			ele : '[name="userPassword"]',
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val == ''){
					return REGISTER_ERROR.USER_PWD.NULL;
				}
				if(!$.check.isPwd(_val)){
					return REGISTER_ERROR.USER_PWD.ERROR;
				}
				return true;
			}
		},{									//确认密码校验
			ele : '#confrimPwd',
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				var _pwd = $.trim($('#registerForm [name="userPassword"]').val());
				if(_val == ''){
					return REGISTER_ERROR.CONF_PWD.NULL;
				}
				if(_val !== _pwd){
					return REGISTER_ERROR.CONF_PWD.ERROR;
				}
				return true;
			}
		},
		{									//QQ校验
			ele : '[name="userQq"]',
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(!$.check.isQQ(_val)){
					return REGISTER_ERROR.QQ.ERROR;
				}
				return true;
			}
		}],$('#registerForm'));
		
		jQuery("#homeBtn").click(function(){ location.href=window.frontPath+"home"; } );
		
	})();